﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace GTA
{
    public partial class FrmMain : BaseForm
    {
        #region Local Objects
        private ContextMenuStrip ctxInformativeSummaryFilterProjects;
        private ContextMenuStrip ctxInformativeSummaryFilterArchitects;
        private ContextMenuStrip ctxInformativeSummaryFilterStates;
        private ContextMenuStrip ctxInformativeSummaryFilterCategories;

        private bool LoadAlertsKeepAlive = true;
        private bool LoadInformativeSummaryProjectsKeepAlive = true;
        private bool LoadInformativeSummaryUsersKeepAlive = true;
        private bool LoadInformativeSummaryCategoriesKeepAlive = true;
        private bool LoadInformativeSummaryStatesKeepAlive = true;

        private Thread trdAlerts;
        private Thread trdInformativeSummaryProjects;
        private Thread trdInformativeSummaryUsers;
        private Thread trdInformativeSummaryCategories;
        private Thread trdInformativeSummaryStates;
        #endregion

        #region Form Start
        public FrmMain()
        {
            InitializeComponent();
            StartForm();
        }
        private void FrmMain_Load(object sender, EventArgs e)
        {
        }
        private void StartForm()
        {
            try
            {
                lblLoggedUser.Text = Program.LoggedUser.Name + " (" + Program.LoggedUser.Login + ")";
                BuildInformativeSummaryContextMenuFilters();
                resumoToolStripMenuItem.Checked = Program.SystemConfiguration.ShowInformativeSummary;
                pnlInformativeSummary.Size = new Size(Program.SystemConfiguration.InformativeSummarySize, pnlInformativeSummary.Height);
                LoadInformativeSummaryListsHeight();
                if (Program.SystemConfiguration.ShowInformativeSummary)
                    StartInformativeSummaryProcessTimer();
                StartAlertsProcessTimer();
                SetUserPrifleAccess();
            }
            catch (Exception ex)
            {
                HandleException("Inicializar a tela principal", ex);
            }
        }
        private void SetUserPrifleAccess()
        {
            //Menu Tarefas
            tasksToolStripMenuItem.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(tasksToolStripMenuItem.Tag)) == 0);

            //Menu Disponibilidade dos Usuários
            toolStripMenuItem2.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem2.Tag)) == 0);

            //Menu Performance Area
            toolStripMenuItem3.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem3.Tag)) == 0);

            //Menu Visualizar Resumo Informativo
            if (!Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(resumoToolStripMenuItem.Tag)) == 0))
            {
                resumoToolStripMenuItem.Checked = false;
                resumoToolStripMenuItem.Enabled = false;
            }

            //Menu Configurações Grupos
            gruposToolStripMenuItem.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(gruposToolStripMenuItem.Tag)) == 0);

            //Menu Configurações Gestão de Usuários
            gestaoDeUsuariosToolStripMenuItem.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(gestaoDeUsuariosToolStripMenuItem.Tag)) == 0);

            //Menu Permissões Perfil de Acesso
            toolStripMenuItem10.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem10.Tag)) == 0);

            //Menu Change Request Results
            toolStripMenuItem5.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem5.Tag)) == 0);

            //Menu Motivos Change Request
            toolStripMenuItem6.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem6.Tag)) == 0);

            //Menu Classificação Histórico Geral
            toolStripMenuItem11.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem6.Tag)) == 0);

            //Menu Categorias das Tarefas
            toolStripMenuItem7.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem7.Tag)) == 0);

            //Menu Status das Tarefas
            toolStripMenuItem8.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem8.Tag)) == 0);

            //Menu Relatorio Quantidade Tarefas
            quantidadesDeTarefasToolStripMenuItem.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(quantidadesDeTarefasToolStripMenuItem.Tag)) == 0);

            //Menu Relatorio Historico Interrupções - Change Request
            historicoDeInterrupcoesDasTarefasToolStripMenuItem.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(historicoDeInterrupcoesDasTarefasToolStripMenuItem.Tag)) == 0);

            //Menu Relatorio Historico Interrupções - Geral
            toolStripMenuItem1.Enabled = Program.LoggedUser.UserProfile.FunctionalityList.Exists(it => it.ID.CompareTo(Convert.ToInt32(toolStripMenuItem1.Tag)) == 0);
        }
        private void LoadInformativeSummaryListsHeight()
        {
            lstTasksArchitects.Size = new Size(lstTasksArchitects.Size.Width, Program.SystemConfiguration.InformativeSummaryLstTasksArchitectsHiehgt);
            lstTasksProjects.Size = new Size(lstTasksProjects.Size.Width, Program.SystemConfiguration.InformativeSummaryLstTasksProjectsHiehgt);
            lstTasksStates.Size = new Size(lstTasksStates.Size.Width, Program.SystemConfiguration.InformativeSummaryLstTasksStatesHiehgt);
            lstTasksCategories.Size = new Size(lstTasksCategories.Size.Width, Program.SystemConfiguration.InformativeSummaryLstTasksCategoriesHiehgt);
        }
        #endregion

        #region Form End
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            CloseForm();
        }
        #endregion

        #region Events
        private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            statusStrip.Visible = statusBarToolStripMenuItem.Checked;
        }
        private void CascadeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.Cascade);
        }
        private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileVertical);
        }
        private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.TileHorizontal);
        }
        private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LayoutMdi(MdiLayout.ArrangeIcons);
        }
        private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (Form childForm in MdiChildren)
            {
                childForm.Close();
            }
        }
        private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowAbout();
        }
        private void optionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowOptions();
        }
        private void tasksToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowPendingScenarios();
        }
        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            ShowArchitectureDisponibility();
        }
        private void toolStripMenuItem3_Click(object sender, EventArgs e)
        {
            ShowSectorPerformance();
        }
        private void taskFieldsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowTaskFields();
        }
        private void resumoToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        {
            ShowPanelInformativeSummary(resumoToolStripMenuItem.Checked);
        }
        private void pnlInformativeSummary_Resize(object sender, EventArgs e)
        {
            SaveInformativeSummaryPanelSize();
        }
        private void lstTasksProjects_Resize(object sender, EventArgs e)
        {
            lstTasksProjects.Columns[0].Width = lstTasksProjects.Size.Width - lstTasksProjects.Columns[1].Width - 25;
        }
        private void lstTasksArchitects_Resize(object sender, EventArgs e)
        {
            lstTasksArchitects.Columns[0].Width = lstTasksArchitects.Size.Width - lstTasksArchitects.Columns[1].Width - 25;
        }
        private void lstTasksStates_Resize(object sender, EventArgs e)
        {
            lstTasksStates.Columns[0].Width = lstTasksStates.Size.Width - lstTasksStates.Columns[1].Width - 25;
        }
        private void lstTasksCategories_Resize(object sender, EventArgs e)
        {
            lstTasksCategories.Columns[0].Width = lstTasksCategories.Size.Width - lstTasksCategories.Columns[1].Width - 25;
        }
        private void splitterLstTasksProjects_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SaveLstTasksProjectsHeight();
        }
        private void splitterLstTasksArchitects_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SaveLstTasksArchitectsHeight();
        }
        private void splitterLstTasksStates_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SaveLstTasksStatesHeight();
        }
        private void splitterLstTasksCategories_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SaveLstTasksCategoriesHeight();
        }
        private void lstTasksProjects_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstTasksProjects, e.Column == 0 ? OrdenacaoListView.Tipo.Alfabetica : OrdenacaoListView.Tipo.Numerica, ref columnOrder, ref sortOrder, e.Column);
        }
        private void lstTasksArchitects_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstTasksArchitects, e.Column == 0 ? OrdenacaoListView.Tipo.Alfabetica : OrdenacaoListView.Tipo.Numerica, ref columnOrder, ref sortOrder, e.Column);
        }
        private void lstTasksStates_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstTasksStates, e.Column == 0 ? OrdenacaoListView.Tipo.Alfabetica : OrdenacaoListView.Tipo.Numerica, ref columnOrder, ref sortOrder, e.Column);
        }
        private void lstTasksCategories_ColumnClick(object sender, ColumnClickEventArgs e)
        {
            SortList(lstTasksCategories, e.Column == 0 ? OrdenacaoListView.Tipo.Alfabetica : OrdenacaoListView.Tipo.Numerica, ref columnOrder, ref sortOrder, e.Column);
        }
        private void gruposToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowGroups();
        }
        private void gestaoDeUsuariosToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowUserManagement();
        }
        private void alterarSenhaToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowChangePassword();
        }
        private void toolStripMenuItem4_Click(object sender, EventArgs e)
        {
            LogOff();
        }
        private void toolStripMenuItem5_Click(object sender, EventArgs e)
        {
            ShowChangeRequestResults();
        }
        private void toolStripMenuItem6_Click(object sender, EventArgs e)
        {
            ShowChangeRequestMotivation();
        }
        private void restaurarToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RestoreWindow();
        }
        private void fecharToolStripMenuItem_Click(object sender, EventArgs e)
        {
            CloseWindow();
        }
        private void notifyIcon1_DoubleClick(object sender, EventArgs e)
        {
            RestoreWindow();
        }
        private void FrmMain_Resize(object sender, EventArgs e)
        {
            HideWindow();
        }
        private void toolStripMenuItem7_Click(object sender, EventArgs e)
        {
            ShowTaskCategories();
        }
        private void toolStripMenuItem8_Click(object sender, EventArgs e)
        {
            ShowTaskStates();
        }
        private void quantidadesDeTarefasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowReportTaskQuantities();
        }
        private void historicoDeInterrupcoesDasTarefasToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowReportTaskHistory();
        }
        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            ShowReportTaskHistoryGeneral();
        }
        private void toolStripMenuItem10_Click(object sender, EventArgs e)
        {
            ShowProfilerFunctionalitiesManagement();
        }
        private void toolStripMenuItem11_Click(object sender, EventArgs e)
        {
            ShowClassificationHistoryGeneral();
        }
        private void LoadInformativeSummaryProjects_FilterEventProjects(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryProjectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryProjectsFilterProjects();
        }
        private void LoadInformativeSummaryProjects_FilterEventCategories(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryProjectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryProjectsFilterCategories();
        }
        private void LoadInformativeSummaryProjects_FilterEventStates(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryProjectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryProjectsFilterStates();
        }
        private void LoadInformativeSummaryArchitects_FilterEventProjects(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryArchitectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryArchitectsFilterProjects();
        }
        private void LoadInformativeSummaryArchitects_FilterEventCategories(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryArchitectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryArchitectsFilterCategories();
        }
        private void LoadInformativeSummaryArchitects_FilterEventStates(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryArchitectsExecution)).Start();
            SaveFilterConfigurationInformativeSummaryArchitectsFilterStates();
        }
        private void LoadInformativeSummaryStates_FilterEventProjects(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryStatesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryStatesFilterProjects();
        }
        private void LoadInformativeSummaryStates_FilterEventCategories(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryStatesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryStatesFilterCategories();
        }
        private void LoadInformativeSummaryStates_FilterEventStates(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryStatesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryStatesFilterStates();
        }
        private void LoadInformativeSummaryCategories_FilterEventProjects(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryCategoriesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryCategoriesFilterProjects();
        }
        private void LoadInformativeSummaryCategories_FilterEventCategories(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryCategoriesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryCategoriesFilterCategories();
        }
        private void LoadInformativeSummaryCategories_FilterEventStates(object sender, EventArgs e)
        {
            new Thread(new ThreadStart(LoadInformativeSummaryCategoriesExecution)).Start();
            SaveFilterConfigurationInformativeSummaryCategoriesFilterStates();
        }
        #endregion

        #region Methods
        private List<BusinessEntity.Configuration.ProjectFilter> ConvertProjectListToSummaryFilter(List<BusinessEntity.Project> list)
        {
            List<BusinessEntity.Configuration.ProjectFilter> summaryProjects = new List<GTA.BusinessEntity.Configuration.ProjectFilter>();
            if (list != null && list.Count > 0)
            {
                foreach (BusinessEntity.Project itemProject in list)
                {
                    summaryProjects.Add(new GTA.BusinessEntity.Configuration.ProjectFilter()
                    {
                        Id = itemProject.Id,
                        Name = itemProject.Name
                    });
                }
            }
            return summaryProjects;
        }
        private List<BusinessEntity.Configuration.DomainFilter> ConvertTaskDomainListToSummaryDomain(List<BusinessEntity.TaskDomain> list)
        {
            List<BusinessEntity.Configuration.DomainFilter> summaryDomain = new List<GTA.BusinessEntity.Configuration.DomainFilter>();
            if (list != null && list.Count > 0)
            {
                foreach (BusinessEntity.TaskDomain itemState in list)
                {
                    summaryDomain.Add(new GTA.BusinessEntity.Configuration.DomainFilter()
                    {
                        ID = itemState.ID,
                        Description = itemState.Description
                    });
                }
            }
            return summaryDomain;
        }
        private void SaveFilterConfigurationInformativeSummaryProjectsFilterProjects()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterProjects);
                Program.SystemConfiguration.InformativeSummaryFilterProjects.FilterProjectList = ConvertProjectListToSummaryFilter(filter.Project);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryProjectsFilterCategories()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterProjects);
                Program.SystemConfiguration.InformativeSummaryFilterProjects.FilterCategoryList = ConvertTaskDomainListToSummaryDomain(filter.Category);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryProjectsFilterStates()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterProjects);
                Program.SystemConfiguration.InformativeSummaryFilterProjects.FilterStateList = ConvertTaskDomainListToSummaryDomain(filter.State);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryArchitectsFilterProjects()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterArchitects);
                Program.SystemConfiguration.InformativeSummaryFilterArchitects.FilterProjectList = ConvertProjectListToSummaryFilter(filter.Project);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryArchitectsFilterCategories()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterArchitects);
                Program.SystemConfiguration.InformativeSummaryFilterArchitects.FilterCategoryList = ConvertTaskDomainListToSummaryDomain(filter.Category);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryArchitectsFilterStates()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterArchitects);
                Program.SystemConfiguration.InformativeSummaryFilterArchitects.FilterStateList = ConvertTaskDomainListToSummaryDomain(filter.State);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryStatesFilterProjects()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterStates);
                Program.SystemConfiguration.InformativeSummaryFilterStates.FilterProjectList = ConvertProjectListToSummaryFilter(filter.Project);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryStatesFilterCategories()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterStates);
                Program.SystemConfiguration.InformativeSummaryFilterStates.FilterCategoryList = ConvertTaskDomainListToSummaryDomain(filter.Category);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryStatesFilterStates()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterStates);
                Program.SystemConfiguration.InformativeSummaryFilterStates.FilterStateList = ConvertTaskDomainListToSummaryDomain(filter.State);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryCategoriesFilterProjects()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterCategories);
                Program.SystemConfiguration.InformativeSummaryFilterCategories.FilterProjectList = ConvertProjectListToSummaryFilter(filter.Project);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryCategoriesFilterCategories()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterCategories);
                Program.SystemConfiguration.InformativeSummaryFilterCategories.FilterCategoryList = ConvertTaskDomainListToSummaryDomain(filter.Category);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        private void SaveFilterConfigurationInformativeSummaryCategoriesFilterStates()
        {
            try
            {
                BusinessEntity.TaskFilter filter = GetInformativeSummaryFilter(ctxInformativeSummaryFilterCategories);
                Program.SystemConfiguration.InformativeSummaryFilterCategories.FilterStateList = ConvertTaskDomainListToSummaryDomain(filter.State);
                Program.SaveSystemConfiguration();
            }
            catch (Exception ex)
            {
                HandleException("Salvar a configuração de filtro do Resumo Informativo", ex);
            }
        }
        public void BuildInformativeSummaryContextMenuFilters()
        {
            try
            {
                BusinessLogic.GTA bl = new BusinessLogic.GTA();
                List<BusinessEntity.TaskDomain> categories = bl.ListCategories();
                List<BusinessEntity.TaskDomain> states = bl.ListStates();

                ctxInformativeSummaryFilterProjects = new ContextMenuStrip();
                ctxInformativeSummaryFilterArchitects = new ContextMenuStrip();
                ctxInformativeSummaryFilterStates = new ContextMenuStrip();
                ctxInformativeSummaryFilterCategories = new ContextMenuStrip();
                AddFirstToolItemFilterTextRepresentation(ctxInformativeSummaryFilterProjects);
                AddFirstToolItemFilterTextRepresentation(ctxInformativeSummaryFilterArchitects);
                AddFirstToolItemFilterTextRepresentation(ctxInformativeSummaryFilterStates);
                AddFirstToolItemFilterTextRepresentation(ctxInformativeSummaryFilterCategories);

                AddContextMenuItemsProjects(ctxInformativeSummaryFilterProjects, Program.SystemConfiguration.InformativeSummaryFilterProjects, Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master ? Program.Projects : Program.LoggedUser.UserProjects, new EventHandler(LoadInformativeSummaryProjects_FilterEventProjects));
                AddContextMenuItemsDomain("Categorias", ctxInformativeSummaryFilterProjects, Program.SystemConfiguration.InformativeSummaryFilterProjects.FilterCategoryList, categories, new EventHandler(LoadInformativeSummaryProjects_FilterEventCategories));
                AddContextMenuItemsDomain("Status", ctxInformativeSummaryFilterProjects, Program.SystemConfiguration.InformativeSummaryFilterProjects.FilterStateList, states, new EventHandler(LoadInformativeSummaryProjects_FilterEventStates));
                lstTasksProjects.ContextMenuStrip = ctxInformativeSummaryFilterProjects;

                AddContextMenuItemsProjects(ctxInformativeSummaryFilterArchitects, Program.SystemConfiguration.InformativeSummaryFilterArchitects, Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master ? Program.Projects : Program.LoggedUser.UserProjects, new EventHandler(LoadInformativeSummaryArchitects_FilterEventProjects));
                AddContextMenuItemsDomain("Categorias", ctxInformativeSummaryFilterArchitects, Program.SystemConfiguration.InformativeSummaryFilterArchitects.FilterCategoryList, categories, new EventHandler(LoadInformativeSummaryArchitects_FilterEventCategories));
                AddContextMenuItemsDomain("Status", ctxInformativeSummaryFilterArchitects, Program.SystemConfiguration.InformativeSummaryFilterArchitects.FilterStateList, states, new EventHandler(LoadInformativeSummaryArchitects_FilterEventStates));
                lstTasksArchitects.ContextMenuStrip = ctxInformativeSummaryFilterArchitects;

                AddContextMenuItemsProjects(ctxInformativeSummaryFilterStates, Program.SystemConfiguration.InformativeSummaryFilterStates, Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master ? Program.Projects : Program.LoggedUser.UserProjects, new EventHandler(LoadInformativeSummaryStates_FilterEventProjects));
                AddContextMenuItemsDomain("Categorias", ctxInformativeSummaryFilterStates, Program.SystemConfiguration.InformativeSummaryFilterStates.FilterCategoryList, categories, new EventHandler(LoadInformativeSummaryStates_FilterEventCategories));
                AddContextMenuItemsDomain("Status", ctxInformativeSummaryFilterStates, Program.SystemConfiguration.InformativeSummaryFilterStates.FilterStateList, states, new EventHandler(LoadInformativeSummaryStates_FilterEventStates));
                lstTasksStates.ContextMenuStrip = ctxInformativeSummaryFilterStates;

                AddContextMenuItemsProjects(ctxInformativeSummaryFilterCategories, Program.SystemConfiguration.InformativeSummaryFilterCategories, Program.LoggedUser.UserProfile == BusinessEntity.UserManagement.Profiler.Master ? Program.Projects : Program.LoggedUser.UserProjects, new EventHandler(LoadInformativeSummaryCategories_FilterEventProjects));
                AddContextMenuItemsDomain("Categorias", ctxInformativeSummaryFilterCategories, Program.SystemConfiguration.InformativeSummaryFilterCategories.FilterCategoryList, categories, new EventHandler(LoadInformativeSummaryCategories_FilterEventCategories));
                AddContextMenuItemsDomain("Status", ctxInformativeSummaryFilterCategories, Program.SystemConfiguration.InformativeSummaryFilterCategories.FilterStateList, states, new EventHandler(LoadInformativeSummaryCategories_FilterEventStates));
                lstTasksCategories.ContextMenuStrip = ctxInformativeSummaryFilterCategories;
            }
            catch (Exception ex)
            {
                HandleException("Montagem dos filtros do Resumo Informativo.", ex);
            }
        }
        private void AddFirstToolItemFilterTextRepresentation(ContextMenuStrip ctxMenu)
        {
            ctxMenu.Items.Add(new ToolStripMenuItem()
            {
                Text = "Filtro",
                Enabled = false,
                Font = new Font(Font.FontFamily, Font.Size, FontStyle.Bold)
            });
        }
        private void AddContextMenuItemsProjects(ContextMenuStrip ctxMenu, BusinessEntity.Configuration.InformativeSummaryFilter summaryFilter, List<GTA.BusinessEntity.Project> list, EventHandler searchEvent)
        {
            ToolStripMenuItem ctxItem = new ToolStripMenuItem("Projetos");
            ctxItem.Name = "ctxFilterProjects";
            if (list != null && list.Count > 0)
                list.ForEach(it => ctxItem.DropDownItems.Add(new ToolStripMenuItem(it.Name, null, searchEvent)
                {
                    CheckOnClick = true,
                    Tag = it.Name,
                    Checked = summaryFilter.FilterProjectList != null && summaryFilter.FilterProjectList.Exists(itfilter => itfilter.Name.CompareTo(it.Name) == 0)
                }));
            else
                ctxItem.Enabled = false;
            ctxMenu.Items.Add(ctxItem);
        }
        private void AddContextMenuItemsDomain(String prefix, ContextMenuStrip ctxMenu, List<BusinessEntity.Configuration.DomainFilter> filterDomainList, List<GTA.BusinessEntity.TaskDomain> list, EventHandler searchEvent)
        {
            ToolStripMenuItem ctxItem = new ToolStripMenuItem(prefix);
            ctxItem.Name = "ctxFilter" + prefix;
            if (list != null && list.Count > 0)
                list.ForEach(it => ctxItem.DropDownItems.Add(new ToolStripMenuItem(it.Description, null, searchEvent)
                {
                    CheckOnClick = true,
                    Tag = it.Description,
                    Checked = filterDomainList != null && filterDomainList.Exists(itFilter => itFilter.Description.CompareTo(it.Description) == 0)
                }));
            else
                ctxItem.Enabled = false;
            ctxMenu.Items.Add(ctxItem);
        }
        private void ShowPendingScenarios()
        {
            if (!Program.CheckOpenedWindow<FrmTasks>(true))
            {
                FrmTasks wd = new FrmTasks();
                wd.WindowState = FormWindowState.Maximized;
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowArchitectureDisponibility()
        {
            if (!Program.CheckOpenedWindow<FrmDisponibilidadeArquitetos>(true))
            {
                FrmDisponibilidadeArquitetos wd = new FrmDisponibilidadeArquitetos();
                wd.WindowState = FormWindowState.Maximized;
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowSectorPerformance()
        {
            if (!Program.CheckOpenedWindow<FrmPerformanceArea>(true))
            {
                FrmPerformanceArea wd = new FrmPerformanceArea();
                wd.WindowState = FormWindowState.Maximized;
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowTaskFields()
        {
            if (!Program.CheckOpenedWindow<FrmTaskFields>(true))
            {
                FrmTaskFields wd = new FrmTaskFields();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowOptions()
        {
            if (!Program.CheckOpenedWindow<FrmOptions>(true))
            {
                FrmOptions wd = new FrmOptions();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowAbout()
        {
            if (!Program.CheckOpenedWindow<FrmAbout>(true))
            {
                FrmAbout wd = new FrmAbout();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowGroups()
        {
            if (!Program.CheckOpenedWindow<FrmGroups>(true))
            {
                FrmGroups wd = new FrmGroups();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowUserManagement()
        {
            if (!Program.CheckOpenedWindow<FrmUserManagement>(true))
            {
                FrmUserManagement wd = new FrmUserManagement();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowChangePassword()
        {
            if (!Program.CheckOpenedWindow<FrmChangePassword>(true))
            {
                FrmChangePassword wd = new FrmChangePassword();
                wd.ShowInTaskbar = false;
                wd.ShowDialog(this);
            }
        }
        private void ShowChangeRequestResults()
        {
            if (!Program.CheckOpenedWindow<FrmChangeRequestResults>(true))
            {
                FrmChangeRequestResults wd = new FrmChangeRequestResults();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowChangeRequestMotivation()
        {
            if (!Program.CheckOpenedWindow<FrmChangeRequestMotivation>(true))
            {
                FrmChangeRequestMotivation wd = new FrmChangeRequestMotivation();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowPanelInformativeSummary(bool show)
        {
            pnlInformativeSummary.Visible = show;
            Program.SystemConfiguration.ShowInformativeSummary = show;
            Program.SaveSystemConfiguration();
            if (!show)
                CloseInformativeSummaryThreadsTimer();
            else
                StartInformativeSummaryProcessTimer();
        }
        private void ShowReportTaskQuantities()
        {
            if (!Program.CheckOpenedWindow<FrmReportTaskQuantities>(true))
            {
                FrmReportTaskQuantities wd = new FrmReportTaskQuantities();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowTaskCategories()
        {
            if (!Program.CheckOpenedWindow<FrmTaskCategoriesManagement>(true))
            {
                FrmTaskCategoriesManagement wd = new FrmTaskCategoriesManagement();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowTaskStates()
        {
            if (!Program.CheckOpenedWindow<FrmTaskStatesManagement>(true))
            {
                FrmTaskStatesManagement wd = new FrmTaskStatesManagement();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowReportTaskHistory()
        {
            if (!Program.CheckOpenedWindow<FrmReportTaskHistoryChangeRequest>(true))
            {
                FrmReportTaskHistoryChangeRequest wd = new FrmReportTaskHistoryChangeRequest();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowReportTaskHistoryGeneral()
        {
            if (!Program.CheckOpenedWindow<FrmReportTaskHistory>(true))
            {
                FrmReportTaskHistory wd = new FrmReportTaskHistory();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowProfilerFunctionalitiesManagement()
        {
            if (!Program.CheckOpenedWindow<FrmProfilerManagement>(true))
            {
                FrmProfilerManagement wd = new FrmProfilerManagement();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void ShowClassificationHistoryGeneral()
        {
            if (!Program.CheckOpenedWindow<FrmTaskHistoryGeneralClassification>(true))
            {
                FrmTaskHistoryGeneralClassification wd = new FrmTaskHistoryGeneralClassification();
                wd.MdiParent = this;
                wd.Show();
            }
        }
        private void SaveInformativeSummaryPanelSize()
        {
            Program.SystemConfiguration.InformativeSummarySize = pnlInformativeSummary.Width;
            Program.SaveSystemConfiguration();
        }
        private void SaveLstTasksProjectsHeight()
        {
            Program.SystemConfiguration.InformativeSummaryLstTasksProjectsHiehgt = lstTasksProjects.Size.Height;
            Program.SaveSystemConfiguration();
        }
        private void SaveLstTasksArchitectsHeight()
        {
            Program.SystemConfiguration.InformativeSummaryLstTasksArchitectsHiehgt = lstTasksArchitects.Size.Height;
            Program.SaveSystemConfiguration();
        }
        private void SaveLstTasksStatesHeight()
        {
            Program.SystemConfiguration.InformativeSummaryLstTasksStatesHiehgt = lstTasksStates.Size.Height;
            Program.SaveSystemConfiguration();
        }
        private void SaveLstTasksCategoriesHeight()
        {
            Program.SystemConfiguration.InformativeSummaryLstTasksCategoriesHiehgt = lstTasksCategories.Size.Height;
            Program.SaveSystemConfiguration();
        }
        private void CloseForm()
        {
            CloseInformativeSummaryThreadsTimer();
            CloseThreads();
        }
        private void LogOff()
        {
            this.Tag = true;
            this.Close();
        }
        private void RestoreWindow()
        {
            Show();
            this.WindowState = FormWindowState.Maximized;
            this.Activate();
            this.Focus();
        }
        private void CloseWindow()
        {
            CloseForm();
            this.Close();
        }
        private void HideWindow()
        {
            if (WindowState == FormWindowState.Minimized && Program.SystemConfiguration.General.HideOnTryIcon)
                Hide();
        }
        private void CloseThreads()
        {
            StopAlertsProcessTimer();
            CloseInformativeSummaryThreadsTimer();
        }
        #endregion

        #region Alerts Timer Process
        private void StartAlertsProcessTimer()
        {
            LoadAlertsKeepAlive = true;
            trdAlerts = new Thread(new ThreadStart(LoadAlerts));
            trdAlerts.Start();
        }
        private void StopAlertsProcessTimer()
        {
            try
            {
                LoadAlertsKeepAlive = false;
                if (trdAlerts != null)
                    trdAlerts.Abort();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                    throw ex;
            }
        }
        public void RestartAlertsProcessTimer()
        {
            StopAlertsProcessTimer();
            StartAlertsProcessTimer();
        }
        private void LoadAlerts()
        {
            try
            {
                BusinessLogic.Configuration bl = new GTA.BusinessLogic.Configuration();
                while (LoadAlertsKeepAlive)
                {
                    List<BusinessEntity.Configuration.Alert> alerts = bl.ListAlerts(Program.LoggedUser,
                                                                                   new GTA.BusinessEntity.Configuration.AlertFilter()
                                                                                    {
                                                                                        State = GTA.BusinessEntity.Configuration.AlertState.Ativo,
                                                                                        CheckSleep = true
                                                                                    });
                    if (alerts == null)
                        alerts = new List<GTA.BusinessEntity.Configuration.Alert>();

                    ShowAlertEMail(alerts.FindAll(it => it.AlertNotificationTypeList.Exists(itf => itf == GTA.BusinessEntity.Configuration.NotificationType.EMail)));
                    ShowAlertBaloon(alerts.FindAll(it => it.AlertNotificationTypeList.Exists(itf => itf == GTA.BusinessEntity.Configuration.NotificationType.ToolTip)));

                    Thread.Sleep(Program.SystemConfiguration.General.TimeAlert * 1000);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LoadAlertsKeepAlive = false;
                    if (MessageBox.Show("Ocorreu um erro durante a pesquisa de alertas configurados.\r\nDetalhes: " +
                        ex.Message +
                        "\r\n\r\nGostaria de reiniciar o processo?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        StartAlertsProcessTimer();
                }
            }
        }
        public void ShowAlertEMail(List<BusinessEntity.Configuration.Alert> alerts)
        {
            BusinessLogic.Configuration bl = new GTA.BusinessLogic.Configuration();
            if (alerts != null && alerts.Count > 0)
                bl.SendAlertsByEMail(alerts, Program.LoggedUser);
        }
        public void ShowAlertBaloon(List<BusinessEntity.Configuration.Alert> alerts)
        {
            BusinessLogic.Configuration bl = new GTA.BusinessLogic.Configuration();
            alerts = bl.FillAlertsDescription(alerts, Program.LoggedUser);
            alerts.RemoveAll(it => String.IsNullOrEmpty(it.Description));

            if (alerts != null && alerts.Count > 0)
            {
                if (!Program.CheckOpenedWindow<FrmNotityIcon>(true))
                {
                    FrmNotityIcon wd = new FrmNotityIcon(alerts);
                    OpenForm(wd);

                    //Execute the showing up animation.
                    for (Int32 i = 2; i < 250; i += 5)
                    {
                        SetFormLocation(wd, i);
                        Thread.Sleep(8);
                    }
                }
                else
                {
                    FrmNotityIcon wd = Program.GetForm<FrmNotityIcon>();
                    UpdateAlertsOnForms(wd, alerts);
                }
            }
            else
            {
                FrmNotityIcon wd = Program.GetForm<FrmNotityIcon>();
                CloseForm(wd);
            }
        }
        private void SetFormLocation(Form frm, Int32 height)
        {
            if (!frm.IsDisposed)
            {
                if (frm.InvokeRequired)
                    frm.Invoke(new Action<Form, Int32>(SetFormLocation), new Object[] { frm, height });
                else
                {
                    frm.Size = new Size(frm.Size.Width, height);
                    frm.Location = new Point((Screen.PrimaryScreen.WorkingArea.Width) - frm.Size.Width - 10, (Screen.PrimaryScreen.WorkingArea.Height) - frm.Size.Height - 10);
                }
            }
        }
        #endregion

        #region Informative Summary Timer Process
        private void StartInformativeSummaryProcessTimer()
        {
            StartInformativeSummaryProjectsTimer();
            StartInformativeSummaryArchitectsTimer();
            StartInformativeSummaryStatesTimer();
            StartInformativeSummaryCategoriesTimer();
        }
        private void CloseInformativeSummaryThreadsTimer()
        {
            StopInformativeSummaryProjectsTimer();
            StopInformativeSummaryArchitectsTimer();
            StopInformativeSummaryStatesTimer();
            StopInformativeSummaryCategoriesTimer();
        }
        private void StartInformativeSummaryProjectsTimer()
        {
            LoadInformativeSummaryProjectsKeepAlive = true;
            trdInformativeSummaryProjects = new Thread(new ThreadStart(LoadInformativeSummaryProjects));
            trdInformativeSummaryProjects.Start();
        }
        private void StopInformativeSummaryProjectsTimer()
        {
            try
            {
                LoadInformativeSummaryProjectsKeepAlive = false;
                if (trdInformativeSummaryProjects != null)
                    trdInformativeSummaryProjects.Abort();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                    throw ex;
            }
        }
        private void StartInformativeSummaryArchitectsTimer()
        {
            LoadInformativeSummaryUsersKeepAlive = true;
            trdInformativeSummaryUsers = new Thread(new ThreadStart(LoadInformativeSummaryArchitects));
            trdInformativeSummaryUsers.Start();
        }
        private void StopInformativeSummaryArchitectsTimer()
        {
            try
            {
                LoadInformativeSummaryUsersKeepAlive = false;
                if (trdInformativeSummaryUsers != null)
                    trdInformativeSummaryUsers.Abort();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                    throw ex;
            }
        }
        private void StartInformativeSummaryStatesTimer()
        {
            LoadInformativeSummaryStatesKeepAlive = true;
            trdInformativeSummaryStates = new Thread(new ThreadStart(LoadInformativeSummaryStates));
            trdInformativeSummaryStates.Start();
        }
        private void StopInformativeSummaryStatesTimer()
        {
            try
            {
                LoadInformativeSummaryStatesKeepAlive = false;
                if (trdInformativeSummaryStates != null)
                    trdInformativeSummaryStates.Abort();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                    throw ex;
            }
        }
        private void StartInformativeSummaryCategoriesTimer()
        {
            LoadInformativeSummaryCategoriesKeepAlive = true;
            trdInformativeSummaryCategories = new Thread(new ThreadStart(LoadInformativeSummaryCategories));
            trdInformativeSummaryCategories.Start();
        }
        private void StopInformativeSummaryCategoriesTimer()
        {
            try
            {
                LoadInformativeSummaryCategoriesKeepAlive = false;
                if (trdInformativeSummaryCategories != null)
                    trdInformativeSummaryCategories.Abort();
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                    throw ex;
            }
        }
        public void RestartInformativeSummaryProjects()
        {
            StopInformativeSummaryProjectsTimer();
            StartInformativeSummaryProjectsTimer();
        }
        public void RestartInformativeSummaryArchitects()
        {
            StopInformativeSummaryArchitectsTimer();
            StartInformativeSummaryArchitectsTimer();
        }
        public void RestartInformativeSummaryStates()
        {
            StopInformativeSummaryStatesTimer();
            StartInformativeSummaryStatesTimer();
        }
        public void RestartInformativeSummaryCategories()
        {
            StopInformativeSummaryCategoriesTimer();
            StartInformativeSummaryCategoriesTimer();
        }
        private void LoadInformativeSummaryProjects()
        {
            try
            {
                while (LoadInformativeSummaryProjectsKeepAlive)
                {
                    LoadInformativeSummaryProjectsExecution();

                    Thread.Sleep(Program.SystemConfiguration.General.TimeSearchInformativeSummaryProjects * 1000);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LoadInformativeSummaryProjectsKeepAlive = false;
                    if (MessageBox.Show("Ocorreu um erro durante a obtenção do resumo informativo de projetos.\r\nDetalhes: " +
                        ex.Message +
                        "\r\n\r\nGostaria de reiniciar o processo?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        StartInformativeSummaryProjectsTimer();
                }
            }
        }
        private void LoadInformativeSummaryProjectsExecution()
        {
            BusinessLogic.GTA bl = new BusinessLogic.GTA();
            List<BusinessEntity.InformativeSummaryProjects> summary = bl.ListInformativeSummaryProjects(Program.LoggedUser, GetInformativeSummaryFilter(ctxInformativeSummaryFilterProjects));
            BindInformativeSummaryProjectsAssync(summary);
        }
        private void BindInformativeSummaryProjectsAssync(List<GTA.BusinessEntity.InformativeSummaryProjects> summary)
        {
            ClearListView(lstTasksProjects);
            if (summary != null && summary.Count > 0)
            {
                foreach (BusinessEntity.InformativeSummaryProjects item in summary)
                {
                    ListViewItem listItem = new ListViewItem(item.ProjectName);
                    listItem.SubItems.Add(item.TaskQuantity.ToString());
                    AddListViewItem(lstTasksProjects, listItem);
                }
            }
        }
        private void LoadInformativeSummaryArchitects()
        {
            try
            {
                while (LoadInformativeSummaryUsersKeepAlive)
                {
                    LoadInformativeSummaryArchitectsExecution();

                    Thread.Sleep(Program.SystemConfiguration.General.TimeSearchInformativeSummaryArchitects * 1000);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LoadInformativeSummaryUsersKeepAlive = false;
                    if (MessageBox.Show("Ocorreu um erro durante a obtenção do resumo informativo de arquitetos.\r\nDetalhes: " +
                        ex.Message +
                        "\r\n\r\nGostaria de reiniciar o processo?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        StartInformativeSummaryArchitectsTimer();
                }
            }
        }
        private void LoadInformativeSummaryArchitectsExecution()
        {
            BusinessLogic.GTA bl = new BusinessLogic.GTA();
            List<BusinessEntity.InformativeSummaryArchitects> summary = bl.ListInformativeSummaryArchitects(Program.LoggedUser, GetInformativeSummaryFilter(ctxInformativeSummaryFilterArchitects));
            BindInformativeSummaryArchitectsAssync(summary);
        }
        private void BindInformativeSummaryArchitectsAssync(List<GTA.BusinessEntity.InformativeSummaryArchitects> summary)
        {
            ClearListView(lstTasksArchitects);
            if (summary != null && summary.Count > 0)
            {
                foreach (BusinessEntity.InformativeSummaryArchitects item in summary)
                {
                    ListViewItem listItem = new ListViewItem(item.ArchitectName);
                    listItem.SubItems.Add(item.TaskQuantity.ToString());
                    AddListViewItem(lstTasksArchitects, listItem);
                }
            }
        }
        private void LoadInformativeSummaryStates()
        {
            try
            {
                while (LoadInformativeSummaryStatesKeepAlive)
                {
                    LoadInformativeSummaryStatesExecution();

                    Thread.Sleep(Program.SystemConfiguration.General.TimeSearchInformativeSummaryStates * 1000);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LoadInformativeSummaryStatesKeepAlive = false;
                    if (MessageBox.Show("Ocorreu um erro durante a obtenção do resumo informativo de status.\r\nDetalhes: " +
                        ex.Message +
                        "\r\n\r\nGostaria de reiniciar o processo?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        StartInformativeSummaryStatesTimer();
                }
            }
        }
        private void LoadInformativeSummaryStatesExecution()
        {
            BusinessLogic.GTA bl = new BusinessLogic.GTA();
            List<BusinessEntity.InformativeSummaryStates> summary = bl.ListInformativeSummaryStates(Program.LoggedUser, GetInformativeSummaryFilter(ctxInformativeSummaryFilterStates));
            BindInformativeSummaryStatesAssync(summary);
        }
        private void BindInformativeSummaryStatesAssync(List<GTA.BusinessEntity.InformativeSummaryStates> summary)
        {
            ClearListView(lstTasksStates);
            if (summary != null && summary.Count > 0)
            {
                foreach (BusinessEntity.InformativeSummaryStates item in summary)
                {
                    ListViewItem listItem = new ListViewItem(item.StateDescription);
                    listItem.SubItems.Add(item.TaskQuantity.ToString());
                    AddListViewItem(lstTasksStates, listItem);
                }
            }
        }
        private void LoadInformativeSummaryCategories()
        {
            try
            {
                while (LoadInformativeSummaryCategoriesKeepAlive)
                {
                    LoadInformativeSummaryCategoriesExecution();

                    Thread.Sleep(Program.SystemConfiguration.General.TimeSearchInformativeSummaryCategories * 1000);
                }
            }
            catch (Exception ex)
            {
                if (!(ex is ThreadAbortException))
                {
                    LoadInformativeSummaryCategoriesKeepAlive = false;
                    if (MessageBox.Show("Ocorreu um erro durante a obtenção do resumo informativo de categorias.\r\nDetalhes: " +
                        ex.Message +
                        "\r\n\r\nGostaria de reiniciar o processo?", "Erro", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.Yes)
                        StartInformativeSummaryCategoriesTimer();
                }
            }
        }
        private void LoadInformativeSummaryCategoriesExecution()
        {
            BusinessLogic.GTA bl = new BusinessLogic.GTA();
            List<BusinessEntity.InformativeSummaryCategories> summary = bl.ListInformativeSummaryCategories(Program.LoggedUser, GetInformativeSummaryFilter(ctxInformativeSummaryFilterCategories));
            BindInformativeSummaryCategoriesAssync(summary);
        }
        private void BindInformativeSummaryCategoriesAssync(List<GTA.BusinessEntity.InformativeSummaryCategories> summary)
        {
            ClearListView(lstTasksCategories);
            if (summary != null && summary.Count > 0)
            {
                foreach (BusinessEntity.InformativeSummaryCategories item in summary)
                {
                    ListViewItem listItem = new ListViewItem(item.CategoryDescription);
                    listItem.SubItems.Add(item.TaskQuantity.ToString());
                    AddListViewItem(lstTasksCategories, listItem);
                }
            }
        }
        private BusinessEntity.TaskFilter GetInformativeSummaryFilter(ContextMenuStrip ctxMenu)
        {
            BusinessEntity.TaskFilter filter = new GTA.BusinessEntity.TaskFilter();
            filter.Project = new List<GTA.BusinessEntity.Project>();
            foreach (ToolStripMenuItem toolItem in ((ToolStripMenuItem)ctxMenu.Items[1]).DropDownItems)
            {
                if (toolItem.Checked)
                    filter.Project.Add(new GTA.BusinessEntity.Project(0, toolItem.Tag.ToString()));
            }
            filter.Category = new List<GTA.BusinessEntity.TaskDomain>();
            foreach (ToolStripMenuItem toolItem in ((ToolStripMenuItem)ctxMenu.Items[2]).DropDownItems)
            {
                if (toolItem.Checked)
                    filter.Category.Add(new GTA.BusinessEntity.TaskDomain(0, toolItem.Tag.ToString()));
            }
            filter.State = new List<GTA.BusinessEntity.TaskDomain>();
            foreach (ToolStripMenuItem toolItem in ((ToolStripMenuItem)ctxMenu.Items[3]).DropDownItems)
            {
                if (toolItem.Checked)
                    filter.State.Add(new GTA.BusinessEntity.TaskDomain(0, toolItem.Tag.ToString()));
            }
            return filter;
        }
        #endregion

        #region Methods to Assync Operations
        private void ClearListView(ListView lst)
        {
            if (lst.InvokeRequired)
                lst.Invoke(new Action<ListView>(ClearListView), new object[] { lst });
            else
                lst.Items.Clear();
        }
        private void AddListViewItem(ListView lst, ListViewItem item)
        {
            if (lst.InvokeRequired)
                lst.Invoke(new Action<ListView, ListViewItem>(AddListViewItem), new object[] { lst, item });
            else
                lst.Items.Add(item);
        }
        private void OpenForm(Form wd)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<Form>(OpenForm), new object[] { wd });
            else
            {
                wd.Show();
            }
        }
        private void CloseForm(Form wd)
        {
            if (wd != null)
            {
                if (wd.InvokeRequired)
                    wd.Invoke(new Action<Form>(CloseForm), new object[] { wd });
                else
                {
                    if (wd != null)
                        wd.Close();
                }
            }
        }
        private void SetFormMdiParent(Form wd, Form mdiParent)
        {
            if (this.InvokeRequired)
                this.Invoke(new Action<Form, Form>(SetFormMdiParent), new object[] { wd, mdiParent });
            else
            {
                if (wd != null && mdiParent != null && mdiParent.IsMdiContainer)
                    wd.MdiParent = mdiParent;
            }
        }
        private void UpdateAlertsOnForms(BaseFormAlerts wd, List<BusinessEntity.Configuration.Alert> alerts)
        {
            if (wd != null)
            {
                if (wd.InvokeRequired)
                    wd.Invoke(new Action<BaseFormAlerts, List<BusinessEntity.Configuration.Alert>>(UpdateAlertsOnForms), new object[] { wd, alerts });
                else
                    wd.UpdateAlerts(alerts);
            }
        }
        #endregion
    }
}
